/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tesam.gedeon.dao.impl;

import com.tesam.gedeon.dao.DepartmentDao;
import com.tesam.gedeon.entity.Department;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Sistema
 */
@Repository
public class DepartmentDaoImpl  extends SimpleJdbcDaoSupport implements DepartmentDao {
    
    @Autowired
    public DepartmentDaoImpl(DataSource dataSource) {
        setDataSource(dataSource);
    }
    
    @Override
    public List<Department> getListByCountry(Department department){
        List<Department> result = new ArrayList();
        
        try{ 
            result = getJdbcTemplate().query("select  code , name from department "
                    + "where deleted = 0  and upper(code_country) = '"+department.getCountry().getCode().toUpperCase()+"'" 
                     , new BeanPropertyRowMapper<Department>(Department.class));
             
        }catch(Exception e){
            System.out.println("getListByCountry : "+e.getMessage());
        }
        
        return result ;
    }
    
}
